package com.google.android.play.core.assetpacks;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import c.b.a.c.a.c.a;
import c.b.a.c.a.c.k;
import c.b.a.c.a.c.o;
import c.b.a.c.a.c.o0;
import c.b.a.c.a.g.e;
import c.b.a.c.a.g.g;
import c.b.a.c.a.g.p;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

final class q implements i3 {
    /* access modifiers changed from: private */
    public static final a f = new a("AssetPackServiceImpl");
    private static final Intent g = new Intent("com.google.android.play.core.assetmoduleservice.BIND_ASSET_MODULE_SERVICE").setPackage("com.android.vending");
    /* access modifiers changed from: private */

    /* renamed from: a  reason: collision with root package name */
    public final String f2596a;

    /* renamed from: b  reason: collision with root package name */
    private final y0 f2597b;
    /* access modifiers changed from: private */

    /* renamed from: c  reason: collision with root package name */
    public k<o0> f2598c;
    /* access modifiers changed from: private */

    /* renamed from: d  reason: collision with root package name */
    public k<o0> f2599d;
    /* access modifiers changed from: private */
    public final AtomicBoolean e = new AtomicBoolean();

    q(Context context, y0 y0Var) {
        this.f2596a = context.getPackageName();
        this.f2597b = y0Var;
        if (o.a(context)) {
            this.f2598c = new k(c.b.a.c.a.f.a.a(context), f, "AssetPackService", g, j3.f2551a);
            this.f2599d = new k(c.b.a.c.a.f.a.a(context), f, "AssetPackService-keepAlive", g, k3.f2563a);
        }
        f.c("AssetPackService initiated.", new Object[0]);
    }

    static /* synthetic */ ArrayList e(Collection collection) {
        ArrayList arrayList = new ArrayList(collection.size());
        Iterator it = collection.iterator();
        while (it.hasNext()) {
            Bundle bundle = new Bundle();
            bundle.putString("module_name", (String) it.next());
            arrayList.add(bundle);
        }
        return arrayList;
    }

    static /* synthetic */ List f(q qVar, List list) {
        ArrayList arrayList = new ArrayList();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            b next = c.b((Bundle) list.get(i), qVar.f2597b).e().values().iterator().next();
            if (next == null) {
                f.e("onGetSessionStates: Bundle contained no pack.", new Object[0]);
            }
            if (w1.c(next.f())) {
                arrayList.add(next.e());
            }
        }
        return arrayList;
    }

    /* access modifiers changed from: private */
    public final void g(int i, String str, int i2) {
        if (this.f2598c != null) {
            f.f("notifyModuleCompleted", new Object[0]);
            p pVar = new p();
            this.f2598c.c(new h(this, pVar, i, str, pVar, i2));
            return;
        }
        throw new v0("The Play Store app is not installed or is an unofficial version.", i);
    }

    static /* synthetic */ Bundle l() {
        Bundle bundle = new Bundle();
        bundle.putInt("playcore_version_code", 10702);
        ArrayList arrayList = new ArrayList();
        arrayList.add(0);
        arrayList.add(1);
        bundle.putIntegerArrayList("supported_compression_formats", arrayList);
        bundle.putIntegerArrayList("supported_patch_formats", new ArrayList());
        return bundle;
    }

    /* access modifiers changed from: private */
    public static Bundle m(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("session_id", i);
        return bundle;
    }

    /* access modifiers changed from: private */
    public static Bundle n(int i, String str) {
        Bundle m = m(i);
        m.putString("module_name", str);
        return m;
    }

    static /* synthetic */ Bundle r(int i, String str, String str2, int i2) {
        Bundle n = n(i, str);
        n.putString("slice_id", str2);
        n.putInt("chunk_number", i2);
        return n;
    }

    private static <T> e<T> v() {
        f.e("onError(%d)", -11);
        return g.a(new a(-11));
    }

    public final e<List<String>> a() {
        if (this.f2598c == null) {
            return v();
        }
        f.f("syncPacks", new Object[0]);
        p pVar = new p();
        this.f2598c.c(new f(this, pVar, pVar));
        return pVar.a();
    }

    public final void b(int i, String str) {
        g(i, str, 10);
    }

    public final synchronized void c() {
        if (this.f2599d != null) {
            f.f("keepAlive", new Object[0]);
            if (!this.e.compareAndSet(false, true)) {
                f.f("Service is already kept alive.", new Object[0]);
                return;
            }
            p pVar = new p();
            this.f2599d.c(new k(this, pVar, pVar));
            return;
        }
        f.g("Keep alive connection manager is not initialized.", new Object[0]);
    }

    public final void j(List<String> list) {
        if (this.f2598c != null) {
            f.f("cancelDownloads(%s)", list);
            p pVar = new p();
            this.f2598c.c(new e(this, pVar, list, pVar));
        }
    }

    public final void o(int i) {
        if (this.f2598c != null) {
            f.f("notifySessionFailed", new Object[0]);
            p pVar = new p();
            this.f2598c.c(new i(this, pVar, i, pVar));
            return;
        }
        throw new v0("The Play Store app is not installed or is an unofficial version.", i);
    }

    public final e<ParcelFileDescriptor> p(int i, String str, String str2, int i2) {
        if (this.f2598c == null) {
            return v();
        }
        f.f("getChunkFileDescriptor(%s, %s, %d, session=%d)", str, str2, Integer.valueOf(i2), Integer.valueOf(i));
        p pVar = new p();
        this.f2598c.c(new j(this, pVar, i, str, str2, i2, pVar));
        return pVar.a();
    }

    public final void q(int i, String str, String str2, int i2) {
        if (this.f2598c != null) {
            f.f("notifyChunkTransferred", new Object[0]);
            p pVar = new p();
            this.f2598c.c(new g(this, pVar, i, str, str2, i2, pVar));
            return;
        }
        throw new v0("The Play Store app is not installed or is an unofficial version.", i);
    }
}
